home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9291 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: web.cae.ca!usenet
  2. From: fraserh@cae.ca (Fraser Hutchinson)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ gurus, I have a question for you!
  5. Date: 29 Feb 1996 18:40:37 GMT
  6. Organization: CAE Electronics Ltd.
  7. Message-ID: <4h4rv5$mct@web.cae.ca>
  8. References: <31281804.687F@iglou.com>
  9. NNTP-Posting-Host: pch63.cae.ca
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.7
  13.  
  14. In article <31281804.687F@iglou.com>, panther@iglou.com says...
  15. >
  16. >How is it possible to check if a variable has been
  17. >initialized yet?  If I do 'if ( !a ) { int a = 1 }' I get
  18.                                         ^^^     
  19.   You cannot check the value of an undeclared variable, and if you 
  20.   previously declared a, you cannot redeclare it again like this.
  21.  
  22. >an error message.  Please, any help would be great.  Reply
  23. >to the group or in mail.  Thanks in advance!
  24. >
  25. >Abe L. Getchell
  26.  
  27.  
  28. However, this *should* work (I haven't verified it....
  29.  
  30.   int a;
  31.  
  32.   if(!a) 
  33.     int a = 1;
  34.  
  35. which declares a new integer a whose scope and lifetime is the duration
  36. of the if statement.
  37.  
  38. So, given this, I would suspect that you did not declare a before eval'ing
  39. it above.
  40.  
  41.  
  42. ciao,
  43.  
  44. Fraser
  45.  
  46.